package com.example.xuanke.controller;

import com.example.xuanke.pojo.Result;
import com.example.xuanke.pojo.Student;
import com.example.xuanke.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result getAll(){
        List<Student> students = studentService.getAll();
        return Result.success("获取学生信息成功",students);
    }

    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.add(student);
        return Result.success("添加学生信息成功",student);
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success("更新学生信息成功",student);
    }

    @DeleteMapping
    public Result delete(Integer id){
        studentService.delete(id);
        return Result.success("删除学生信息成功",id);
    }
}
